package com.aat.dxfy.http;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;

public class Base64ImageUtil {

	// 图片转化成base64字符串
	// 将文件系统的图片文件转化为字节数组字符串，并对其进行Base64编码处理
	public static String image2Base64Str(String imgFile) {
		InputStream in = null;
		byte[] data = null;
		// 读取图片字节数组
		try {
			in = new FileInputStream(imgFile);
			data = new byte[in.available()];
			in.read(data);
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		// 对字节数组Base64编码
		return Base64.getEncoder().encodeToString(data);
	}

	// 图片转化成base64字符串
	// 将网络图片文件转化为字节数组字符串，并对其进行Base64编码处理
	public static String urlImage2Base64Str(String url) {
		byte[] data = HttpPoolUtil.getImg(url);
		// 对字节数组Base64编码
		return Base64.getEncoder().encodeToString(data);
	}
	
	/*
	 public static void main(String[] args) {
		String url = "http://dianxiaohuo-st-image.oss-cn-beijing.aliyuncs.com/3316/20180522/3316_1012_124_12418052222787167_p73011131hm4.jpg";
		System.out.println(urlImage2Base64Str(url));
	}
	 */

}